const fs = require('fs');
const { onSave } = require('./mysql');

onSave().then((res) => {
  const batch = 1000;
  let start = 0,
    end = batch;
  const counts = Math.ceil(res.length / batch);
  let count = 1;
  while (start < res.length) {
    const output = res
      .slice(start, end)
      .map((item) => item.result)
      .join('\n');
    fs.writeFileSync('输出.txt', output, { flag: 'a' });
    end += batch;
    start += batch;
    console.log(`数据已写入${((count / counts) * 100).toFixed(0)}%`);
    count++;
  }
  console.log('数据已处理完毕， 请按 Ctrl+C 退出程序。');
});
